package rocket.mq.provider.starter.controller;

import java.util.UUID;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zss
 * @date 2021/9/18 18:19
 * @Email:451682479@qq.com
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    DefaultMQProducer defaultMQProducer;

    @GetMapping("test1")
    public String test1() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {

        int i = 0;

        while (true) {

            System.out.println("开始发送消息 --- " + i++);

            String content = UUID.randomUUID().toString();

            Message sendMsg = new Message("TestTopic", "TestTag", content.getBytes());

            defaultMQProducer.send(sendMsg);

            Thread.sleep(500);
        }
    }
}
